package com.demo.nacos.serviceb;

import com.demo.nacos.serviceb.clients.ServiceAClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
@RequiredArgsConstructor(onConstructor=@__({@Autowired,@Lazy}))
public class IndexController {

    private final ServiceAClient serviceAClient;

    @Value("${nacosconfig.hello:default}")
    private String hello;
    @Value("${nacosconfig.shared:default}")
    private String shared;
    @Value("${nacosconfig.ext:default}")
    private String ext;

    @GetMapping("/hello")
    public Object hello(){
        return "hello, this is servcie B";
    }
    @GetMapping("/my_say")
    public Object say(){
        return "hello, this is servcie B, this is say test";
    }
    @GetMapping("/get_a_say")
    public Object getBSay(){
        String says = serviceAClient.getMySay();
        return "hello, this is servcie B, servcie A says that: "+says;
    }
    @GetMapping("/get_nacos_config")
    public Object getNacosConfig(){
        return String.format("%s\n%s\n%s",hello,shared,ext);
    }
}
